#zhe800 url_name validator
class UrlNameValidator < ActiveModel::EachValidator
  REGEXP = /^\w+_\d+$/
  def validate_each(record, attribute, value)
    record.errors.add attribute, (options[:message] || I18n.t('rails_validation.url_name.invalid')) unless value =~ REGEXP
  end
end
module ActiveModel
  module Validations
    module HelperMethods
      def validates_url_name_of(*attr_names)
        validates_with UrlNameValidator, _merge_attributes(attr_names)
      end
    end
  end
end
